package com.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.core.common.model.json.DataGrid;
import org.jeecgframework.core.constant.Globals;
import org.jeecgframework.core.util.ExceptionUtil;
import org.jeecgframework.core.util.ResourceUtil;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
import org.jeecgframework.poi.excel.entity.vo.TemplateExcelConstants;
import org.jeecgframework.tag.core.easyui.TagUtil;
import org.jeecgframework.web.system.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import com.entity.CheckerDdata;
import com.entity.CheckerInfo;
import com.entity.CheckerMdata;
import com.entity.PowerRateRecovery;
import com.entity.TeamInfo;
import com.service.IBigShowService;
import com.util.AppUtils;

@Controller
@RequestMapping("/homeController")
public class HomeController {
	private static final Logger logger = Logger.getLogger(EchartsController.class);
	
	private SystemService systemService;
	
	private IBigShowService bigShowService;	
	
	@Autowired
	public void setSystemService(SystemService systemService) {
		this.systemService = systemService;
	}

	@Autowired
	public void setBigShowService(IBigShowService bigShowService) {
		this.bigShowService = bigShowService;
	}

	@RequestMapping(params = "show") 
    public String showHomePage(HttpServletRequest request) {  
		String teamId = request.getParameter("team");
       
        if(StringUtils.isNotBlank(teamId) && AppUtils.isInteger(teamId)){
        	TeamInfo teamInfo = systemService.get(TeamInfo.class, Integer.parseInt(teamId));
        	request.setAttribute("TeamInfo", teamInfo);
        	request.setAttribute("teamId", teamInfo.getBzId());
        }
        
        
        return "com/buss/home";  
    }  
	
	/**
	 * 班组电费回收情况
	 * 
	 * @param request
	 * @return 
	 */
	@RequestMapping(params = "getTeamPowerRateRecovery")
	@ResponseBody
	public AjaxJson getTeamPowerRateRecovery(HttpServletRequest request) {
		String teamId = request.getParameter("team");
		// System.out.println("getTeamPowerRateRecovery TeamID:"+teamId);
		AjaxJson j = new AjaxJson();
		j.setSuccess(true);
		String  content = bigShowService.getTeamPowerRateRecovery(teamId);
		j.setMsg(content);
		 
		return j;
	}
	
	/**
	 * 班组当月巡视情况
	 * 
	 * @param request
	 * @return 
	 */
	@RequestMapping(params = "getInspections")
	@ResponseBody
	public AjaxJson getInspections(HttpServletRequest request) {
		String teamId = request.getParameter("team");
		// System.out.println("getInspections TeamID:"+teamId);
		AjaxJson j = new AjaxJson();
		j.setSuccess(true);
		String  content = bigShowService.getInspections(teamId);
		j.setMsg(content);
		 
		return j;
	}
	
	/**
	 * 班组重点工作情况
	 * 
	 * @param request
	 * @return 
	 */
	@RequestMapping(params = "getKeyWork")
	@ResponseBody
	public AjaxJson getKeyWork(HttpServletRequest request) {
		String teamId = request.getParameter("team");
		// System.out.println("getInspections TeamID:"+teamId);
		AjaxJson j = new AjaxJson();
		j.setSuccess(true);
		List<Map<String,Object>> kwList = bigShowService.getKeyWork(teamId);
		j.setObj(kwList);
		 
		return j;
	}
	
	
	/**
	 *  班组列表页面跳转
	 * 
	 *  @return
	 */
	@RequestMapping(params = "teamListR")
	public String teamListR(HttpServletRequest request) {
		
		return "com/buss/teamList";
	}
	
	/***
	 * 班组信息列表
	 * @param request
	 * @param response
	 * @param dataGrid
	 * @param ti
	 */
	@RequestMapping(params = "teamGrid")
	public void teamGrid(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid, TeamInfo ti) {
		CriteriaQuery cq = new CriteriaQuery(TeamInfo.class, dataGrid);

		//班组编号
        String bzId = ti.getBzId();
        if(StringUtils.isNotEmpty(bzId)) {
        	bzId = bzId.trim();
        	if(bzId.lastIndexOf("%")==-1){
        		bzId = "%"+bzId + "%";
            }
        	cq.like("bzId", bzId);
        }        
        //班组名称
        String bzName = ti.getBzName();
        if(StringUtils.isNotEmpty(bzName)) {
        	bzName = bzName.trim();
        	if(bzName.lastIndexOf("%")==-1){
        		bzName = "%"+bzName + "%";
            }
        	cq.like("bzName", bzName);
        }
         
        cq.add();
        this.systemService.getDataGridReturn(cq, true);
        List<TeamInfo> tiLst = dataGrid.getResults();
        for(TeamInfo team:tiLst){
           if(team.getState()!=null  && team.getState().equals("1")){
        	   team.setState("启用");
           }else if(team.getState()!=null  && team.getState().equals("0")){
        	   team.setState("禁用");
           }
           if(team.getShowcol()!=null  && team.getShowcol().equals("1")){
        	   team.setShowcol("高压费控转换率");
           }else if(team.getShowcol()!=null  && team.getShowcol().equals("0")){
        	   team.setShowcol("低压费控推广户数");
           }
        }
        
		TagUtil.datagrid(response, dataGrid);
	}
	
	/**
	 * 添加班组页面跳转
	 *
	 * @return
	 */
	@RequestMapping(params = "aouTeam")
	public ModelAndView aouGroup(TeamInfo team, HttpServletRequest req) {
		if (team.getId() != null) {
			team = systemService.getEntity(TeamInfo.class, team.getId());
			req.setAttribute("team", team);
		}
		
		return new ModelAndView("com/buss/addTeam");
	}
	
	/**
	 * 编辑保存班组
	 *
	 * @param team
	 * @return
	 */
	@RequestMapping(params = "saveTeam")
	@ResponseBody
	public AjaxJson saveTeam(TeamInfo team, HttpServletRequest request) {
		String message = null;
		AjaxJson j = new AjaxJson();
		if (StringUtil.isNotEmpty(team.getId())) {
			systemService.updateEntitie(team);
			
			message = "更新班组【"+team.getBzName()+"】成功";
			systemService.addLog(message, Globals.Log_Leavel_INFO, Globals.Log_Type_UPDATE);
		} else {			
			systemService.save(team);
			
			message = "添加班组【"+team.getBzName()+"】成功";
			systemService.addLog(message, Globals.Log_Leavel_INFO, Globals.Log_Type_INSERT);
		}
		j.setMsg(message);
		return j;
	}
	
	/**
	 * 删除班组
	 *
	 * @return
	 */
	@RequestMapping(params = "delTeam")
	@ResponseBody
	public AjaxJson delTeam(TeamInfo team, HttpServletRequest request) {
		String message = null;
		team = systemService.getEntity(TeamInfo.class, team.getId());
		
		AjaxJson j = new AjaxJson();
		List<Object> listGC = systemService.findHql("from CheckerInfo where bzId=?", team.getBzId());
		if(listGC!=null && listGC.size()>0){
			message = "请先删除班组下所有用检员";
			j.setMsg(message);
			return j;
		}		
		
		message = "删除班组【"+team.getBzName()+"】成功";
		systemService.delete(team);
		
		systemService.addLog(message, Globals.Log_Leavel_INFO, Globals.Log_Type_DEL);
		j.setMsg(message);
		return j;
	}
	
	
	/**
	 *  用检员列表页面跳转
	 * 
	 *  @return
	 */
	@RequestMapping(params = "checkerListR")
	public String checkerListR(HttpServletRequest request) {
		
		return "com/buss/checkerList";
	}
	
	/***
	 * 用检员信息列表
	 * @param request
	 * @param response
	 * @param dataGrid
	 * @param ti
	 */
	@RequestMapping(params = "checkerGrid")
	public void checkerGrid(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid, CheckerInfo ci) {
		CriteriaQuery cq = new CriteriaQuery(CheckerInfo.class, dataGrid);
      
        //班组名称
        String bzName = ci.getBzName();
        if(StringUtils.isNotEmpty(bzName)) {
        	bzName = bzName.trim();
        	if(bzName.lastIndexOf("%")==-1){
        		bzName = "%"+bzName + "%";
            }
        	cq.like("bzName", bzName);
        }
        
        //用检员名称
        String checkerName = ci.getCheckerName();
        if(StringUtils.isNotEmpty(checkerName)) {
        	checkerName = checkerName.trim();
        	if(checkerName.lastIndexOf("%")==-1){
        		checkerName = "%"+checkerName + "%";
            }
        	cq.like("checkerName", checkerName);
        }
         
        cq.add();
        this.systemService.getDataGridReturn(cq, true);
        List<CheckerInfo> ciLst = dataGrid.getResults();
        for(CheckerInfo checker:ciLst){
           if(checker.getState()!=null  && checker.getState().equals("1")){
        	   checker.setState("启用");
           }else{
        	   checker.setState("禁用");
           }
        }
        
		TagUtil.datagrid(response, dataGrid);
	}
	
	/**
	 * 添加用检员页面跳转
	 *
	 * @return
	 */
	@RequestMapping(params = "aouChecker")
	public ModelAndView aouChecker(CheckerInfo checker, HttpServletRequest req) {
		if (checker.getId() != null) {
			checker = systemService.getEntity(CheckerInfo.class, checker.getId());
			req.setAttribute("checker", checker);
		}
		
		setBzList(req);
		
		return new ModelAndView("com/buss/addChecker");
	}
	
	/**
	 * 编辑保存用检员
	 *
	 * @param checker
	 * @return
	 */
	@RequestMapping(params = "saveChecker")
	@ResponseBody
	public AjaxJson saveChecker(CheckerInfo checker, HttpServletRequest request) {
		String message = null;
		AjaxJson j = new AjaxJson();
		if(StringUtils.isNotBlank(checker.getBzId())){
			TeamInfo team = systemService.findUniqueByProperty(TeamInfo.class, "bzId", checker.getBzId());
			checker.setBzName(team.getBzName());
		}
		
		if (StringUtil.isNotEmpty(checker.getId())) {
			systemService.updateEntitie(checker);
			
			message = "更新用检员【"+checker.getCheckerName()+"】成功";
			systemService.addLog(message, Globals.Log_Leavel_INFO, Globals.Log_Type_UPDATE);
		} else {			
			systemService.save(checker);
			
			message = "添加用检员【"+checker.getCheckerName()+"】成功";
			systemService.addLog(message, Globals.Log_Leavel_INFO, Globals.Log_Type_INSERT);
		}
		j.setMsg(message);
		return j;
	}
	
	/**
	 * 删除用检员
	 *
	 * @return
	 */
	@RequestMapping(params = "delChecker")
	@ResponseBody
	public AjaxJson delChecker(CheckerInfo checker, HttpServletRequest request) {
		String message = null;
		checker = systemService.getEntity(CheckerInfo.class, checker.getId());
		
		AjaxJson j = new AjaxJson();
		List<Object> listGC = systemService.findHql("from CheckerMdata where bzId = ? and checkerName = ?", checker.getBzId(),checker.getCheckerName());
		if(listGC!=null && listGC.size()>0){
			message = "请先删除用检员所有的月数据！";
			j.setMsg(message);
			return j;
		}	
		
		listGC = systemService.findHql("from CheckerDdata where bzId = ? and checkerName = ?", checker.getBzId(),checker.getCheckerName());
		if(listGC!=null && listGC.size()>0){
			message = "请先删除用检员所有的日数据！";
			j.setMsg(message);
			return j;
		}
		
		message = "删除用检员【"+checker.getCheckerName()+"】成功";
		systemService.delete(checker);
		
		systemService.addLog(message, Globals.Log_Leavel_INFO, Globals.Log_Type_DEL);
		j.setMsg(message);
		return j;
	}
	
	/**
	 *  电费回收列表页面跳转
	 * 
	 *  @return
	 */
	@RequestMapping(params = "powerRateListR")
	public String powerRateListR(HttpServletRequest req) {
		setBzList(req);
		return "com/buss/powerRateList";
	}
	
	/***
	 * 电费回收信息列表
	 * @param request
	 * @param response
	 * @param dataGrid
	 * @param prr
	 */
	@RequestMapping(params = "powerRateGrid")
	public void powerRateGrid(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid, PowerRateRecovery prr) {
		CriteriaQuery cq = new CriteriaQuery(PowerRateRecovery.class, dataGrid);
      
        //班组名称
        String bzId = prr.getBzId();
        if(StringUtils.isNotEmpty(bzId)) {        	
        	cq.eq("bzId", bzId);
        }
        
        //日期
        String cDate = prr.getcDate();
        if(StringUtils.isNotEmpty(cDate)) {        	
        	cq.eq("cDate", cDate);
        }
         
        cq.add();
        this.systemService.getDataGridReturn(cq, true);
        
		TagUtil.datagrid(response, dataGrid);
	}
	
	/**
	 * 添加电费回收页面跳转
	 *
	 * @return
	 */
	@RequestMapping(params = "aouPowerRate")
	public ModelAndView aouPowerRate(PowerRateRecovery powerRate, HttpServletRequest req) {
		if (powerRate.getId() != null) {
			powerRate = systemService.getEntity(PowerRateRecovery.class, powerRate.getId());
			req.setAttribute("powerRate", powerRate);
		}
		
		setBzList(req);
		
		return new ModelAndView("com/buss/addPowerRate");
	}
	
	/**
	 * 设置班组集合
	 */
	private void setBzList(HttpServletRequest req){
		List<TeamInfo> teamLst =  systemService.findHql("from TeamInfo where state='1'");
		req.setAttribute("teamLst", teamLst);
	}
	
	/**
	 * 编辑保存电费回收信息
	 *
	 * @param powerRate
	 * @return
	 */
	@RequestMapping(params = "savePowerRate")
	@ResponseBody
	public AjaxJson savePowerRate(PowerRateRecovery powerRate, HttpServletRequest request) {
		String message = null;
		AjaxJson j = new AjaxJson();
		if(StringUtils.isNotBlank(powerRate.getBzId())){
			TeamInfo team = systemService.findUniqueByProperty(TeamInfo.class, "bzId", powerRate.getBzId());
			powerRate.setBzName(team.getBzName());
		}
		
		if (StringUtil.isNotEmpty(powerRate.getId())) {
			systemService.updateEntitie(powerRate);
			
			message = "更新【"+powerRate.getBzName()+"|"+powerRate.getcDate()+"】电费回收信息成功";
			systemService.addLog(message, Globals.Log_Leavel_INFO, Globals.Log_Type_UPDATE);
		} else {			
			systemService.save(powerRate);
			
			message = "添加【"+powerRate.getBzName()+"|"+powerRate.getcDate()+"】电费回收信息成功";
			systemService.addLog(message, Globals.Log_Leavel_INFO, Globals.Log_Type_INSERT);
		}
		j.setMsg(message);
		return j;
	}
	
	/**
	 * 删除班组电费回收信息
	 *
	 * @return
	 */
	@RequestMapping(params = "delPowerRate")
	@ResponseBody
	public AjaxJson delPowerRate(PowerRateRecovery powerRate, HttpServletRequest request) {
		String message = null;
		powerRate = systemService.getEntity(PowerRateRecovery.class, powerRate.getId());
		
		AjaxJson j = new AjaxJson();		
		message = "删除【"+powerRate.getBzName()+"|"+powerRate.getcDate()+"】电费回收信息成功";
		systemService.delete(powerRate);
		
		systemService.addLog(message, Globals.Log_Leavel_INFO, Globals.Log_Type_DEL);
		j.setMsg(message);
		return j;
	}
	
	/**
	 *  月数据维护列表页面跳转
	 * 
	 *  @return
	 */
	@RequestMapping(params = "mdataListR")
	public String mdataListR(HttpServletRequest req) {
		setBzList(req);
		return "com/buss/mdataList";
	}
	
	/***
	 * 月数据维护信息列表
	 * @param request
	 * @param response
	 * @param dataGrid
	 * @param cm
	 */
	@RequestMapping(params = "mdataGrid")
	public void mdataGrid(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid, CheckerMdata cm) {
		CriteriaQuery cq = new CriteriaQuery(CheckerMdata.class, dataGrid);
      
        //班组编号
        String bzId = cm.getBzId();
        if(StringUtils.isNotEmpty(bzId)) {        	
        	cq.eq("bzId", bzId);
        }
        
        //用检员
        String checkerName = cm.getCheckerName();
        if(StringUtils.isNotEmpty(checkerName)) {        	
        	cq.eq("checkerName", checkerName);
        }
        
        //月份
        String createMonth = cm.getCreateMonth();
        if(StringUtils.isNotEmpty(createMonth)) {        	
        	cq.eq("createMonth", createMonth);
        }
         
        cq.add();
        this.systemService.getDataGridReturn(cq, true);
 
        
		TagUtil.datagrid(response, dataGrid);
	}
	
	/**
	 * 添加月数据维护页面跳转
	 *
	 * @return
	 */
	@RequestMapping(params = "aouMdata")
	public ModelAndView aouMdata(CheckerMdata mdata, HttpServletRequest req) {
		if (mdata.getId() != null) {
			mdata = systemService.getEntity(CheckerMdata.class, mdata.getId());
			req.setAttribute("mdata", mdata);
		}
		
		setBzList(req);
		
		return new ModelAndView("com/buss/addMdata");
	}
	
	/**
	 * 编辑保存月度数据
	 *
	 * @param mdata
	 * @return
	 */
	@RequestMapping(params = "saveMdata")
	@ResponseBody
	public AjaxJson saveMdata(CheckerMdata mdata, HttpServletRequest request) {
		String message = null;
		AjaxJson j = new AjaxJson();
		if(StringUtils.isNotBlank(mdata.getBzId())){
			TeamInfo team = systemService.findUniqueByProperty(TeamInfo.class, "bzId", mdata.getBzId());
			mdata.setBzName(team.getBzName());
		}
		
		if (StringUtil.isNotEmpty(mdata.getId())) {
			systemService.updateEntitie(mdata);
			
			message = "更新【"+mdata.getBzName()+"|"+mdata.getCreateMonth()+"】月数据成功";
			systemService.addLog(message, Globals.Log_Leavel_INFO, Globals.Log_Type_UPDATE);
		} else {			
			systemService.save(mdata);
			
			message = "添加【"+mdata.getBzName()+"|"+mdata.getCreateMonth()+"】月数据成功";
			systemService.addLog(message, Globals.Log_Leavel_INFO, Globals.Log_Type_INSERT);
		}
		j.setMsg(message);
		return j;
	}
	
	/**
	 * 删除月度数据
	 *
	 * @return
	 */
	@RequestMapping(params = "delMdate")
	@ResponseBody
	public AjaxJson delMdate(CheckerMdata mdata, HttpServletRequest request) {
		String message = null;
		mdata = systemService.getEntity(CheckerMdata.class, mdata.getId());
		
		AjaxJson j = new AjaxJson();		
		message = "删除【"+mdata.getBzName()+"|"+mdata.getCreateMonth()+"】月度数据成功";
		systemService.delete(mdata);
		
		systemService.addLog(message, Globals.Log_Leavel_INFO, Globals.Log_Type_DEL);
		j.setMsg(message);
		return j;
	}
	
	/**
	 * 获取班组下的所有用检员
	 *
	 * @return
	 */
	@RequestMapping(params = "getCheckersByBzId")
	@ResponseBody
	public AjaxJson getCheckersByBzId(String bzId, HttpServletRequest request) {	
		List<CheckerInfo> ciLst = systemService.findHql("from CheckerInfo where bzId = ?", bzId);
		
		AjaxJson j = new AjaxJson();		
		j.setSuccess(true);
		j.setObj(ciLst);
		return j;
	}
	
	/**
	 *  日数据维护列表页面跳转
	 * 
	 *  @return
	 */
	@RequestMapping(params = "ddataListR")
	public String ddataListR(HttpServletRequest req) {
		setBzList(req);
		return "com/buss/ddataList";
	}
	
	/***
	 * 月数据维护信息列表
	 * @param request
	 * @param response
	 * @param dataGrid
	 * @param cm
	 */
	@RequestMapping(params = "ddataGrid")
	public void ddataGrid(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid, CheckerDdata cd) {
		CriteriaQuery cq = new CriteriaQuery(CheckerDdata.class, dataGrid);
      
        //班组编号
        String bzId = cd.getBzId();
        if(StringUtils.isNotEmpty(bzId)) {        	
        	cq.eq("bzId", bzId);
        }
        
        //用检员
        String checkerName = cd.getCheckerName();
        if(StringUtils.isNotEmpty(checkerName)) {        	
        	cq.eq("checkerName", checkerName);
        }
        
        //日期
        String createDate = cd.getCreateDate();
        if(StringUtils.isNotEmpty(createDate)) {        	
        	cq.eq("createDate", createDate);
        }
         
        cq.add();
        this.systemService.getDataGridReturn(cq, true);
 
        
		TagUtil.datagrid(response, dataGrid);
	}
	
	/**
	 * 添加日数据维护页面跳转
	 *
	 * @return
	 */
	@RequestMapping(params = "aouDdata")
	public ModelAndView aouDdata(CheckerDdata ddata, HttpServletRequest req) {
		if (ddata.getId() != null) {
			ddata = systemService.getEntity(CheckerDdata.class, ddata.getId());
			req.setAttribute("ddata", ddata);
		}
		
		setBzList(req);
		
		return new ModelAndView("com/buss/addDdata");
	}
	
	/**
	 * 编辑保存日数据
	 *
	 * @param mdata
	 * @return
	 */
	@RequestMapping(params = "saveDdata")
	@ResponseBody
	public AjaxJson saveDdata(CheckerDdata ddata, HttpServletRequest request) {
		String message = null;
		AjaxJson j = new AjaxJson();
		if(StringUtils.isNotBlank(ddata.getBzId())){
			TeamInfo team = systemService.findUniqueByProperty(TeamInfo.class, "bzId", ddata.getBzId());
			ddata.setBzName(team.getBzName());
		}
		
		if (StringUtil.isNotEmpty(ddata.getId())) {
			systemService.updateEntitie(ddata);
			
			message = "更新【"+ddata.getBzName()+"|"+ddata.getCreateDate()+"】日数据成功";
			systemService.addLog(message, Globals.Log_Leavel_INFO, Globals.Log_Type_UPDATE);
		} else {			
			systemService.save(ddata);
			
			message = "添加【"+ddata.getBzName()+"|"+ddata.getCreateDate()+"】日数据成功";
			systemService.addLog(message, Globals.Log_Leavel_INFO, Globals.Log_Type_INSERT);
		}
		j.setMsg(message);
		return j;
	}
	
	/**
	 * 删除日数据
	 *
	 * @return
	 */
	@RequestMapping(params = "delDdate")
	@ResponseBody
	public AjaxJson delDdate(CheckerDdata ddata, HttpServletRequest request) {
		String message = null;
		ddata = systemService.getEntity(CheckerDdata.class, ddata.getId());
		
		AjaxJson j = new AjaxJson();		
		message = "删除【"+ddata.getBzName()+"|"+ddata.getCreateDate()+"】月度数据成功";
		systemService.delete(ddata);
		
		systemService.addLog(message, Globals.Log_Leavel_INFO, Globals.Log_Type_DEL);
		j.setMsg(message);
		return j;
	}
	
	
	/**
	 * 班组日数据维护模板
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(params = "exportXlsByDdataT")
	public String exportXlsByDdataT(HttpServletRequest request,HttpServletResponse response
			, DataGrid dataGrid,ModelMap modelMap) {		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("exportUserName", ResourceUtil.getSessionUserName().getRealName());
		
        modelMap.put(TemplateExcelConstants.FILE_NAME,"班组重点工作日数据列表");
        modelMap.put(TemplateExcelConstants.PARAMS,new TemplateExportParams("export/template/teamDayData.xls",0));
        modelMap.put(TemplateExcelConstants.MAP_DATA,map);
        return TemplateExcelConstants.JEECG_TEMPLATE_EXCEL_VIEW;
        
	}
	
	/**
	 * 班组日数据导入功能跳转
	 *
	 * @return
	 */
	@RequestMapping(params = "uploadDayForm")
	public ModelAndView uploadDayForm(HttpServletRequest request) {
		 
		
		return new ModelAndView("com/buss/daydata_excel_upload");
	}
	
	/**
	 * 导入班组日数据
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(params = "importDayExcel", method = RequestMethod.POST)
	@ResponseBody
	public AjaxJson importDayExcel(HttpServletRequest request, HttpServletResponse response) {		
		AjaxJson j = new AjaxJson();
		//班组名称
		String bzName = "";
		//用检员
		String checkerName = "";
		//日期
	    String cDate ="";

		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
			MultipartFile file = entity.getValue();// 获取上传文件对象
			ImportParams params = new ImportParams();
			params.setTitleRows(2);
			params.setHeadRows(1);
			params.setNeedSave(true);
			int succCnt = 0;
			int errCnt = 0;
			try {
				List<CheckerDdata> cDdatas = ExcelImportUtil.importExcel(file.getInputStream(),CheckerDdata.class,params);
				List<Object> listGC = null;
				//验证班组及用检员是否存在
				for(CheckerDdata cdata:cDdatas){
					bzName = cdata.getBzName().trim();
					checkerName = cdata.getCheckerName().trim();
					cDate = cdata.getCreateDate().trim();
					
				    listGC = systemService.findHql("from CheckerInfo where bzName = ? and checkerName = ?", bzName,checkerName);
				    if(listGC==null || listGC.size()==0){
				    	  j.setMsg(cdata.getBzName()+"|"+cdata.getCheckerName()+" 班组用检员信息不存,请联系系统管理员！");	
				    	  return j;
				    } 
				    
				    if(cDate.length()!=10 || cDate.indexOf("-")==-1){
				    	j.setMsg(cDate+" 日期格式不正确，参考 yyyy-MM-dd 请检查！");	
				    	return j;
				    }
				}
				
				//班组Map
				List<TeamInfo> listBZ = systemService.findHql("from TeamInfo where state='1'");
				Map bzMap = new HashMap();
				for(TeamInfo ti:listBZ){
					bzMap.put(ti.getBzName(), ti.getBzId());
				}
				
				for(CheckerDdata cdata:cDdatas){
					bzName = cdata.getBzName().trim();
					checkerName = cdata.getCheckerName().trim();
					cDate = cdata.getCreateDate().trim();
				    
				    cdata.setBzId(bzMap.get(bzName).toString());
				    
				    cdata.setBzName(bzName);
				    cdata.setCheckerName(checkerName);
				    cdata.setCreateDate(cDate);
				    try{
				    	this.systemService.save(cdata);
				    	succCnt++;
				    }catch(Exception ex){
				    	errCnt++;
				    	//j.setMsg("文件导入失败！"+ExceptionUtil.getExceptionMessage(ex));
						systemService.addLog("导入班组日数据失败："+cdata.getCreateDate()+"|"+cdata.getBzName()+"|"+cdata.getCheckerName()+"|"+ExceptionUtil.getExceptionMessage(ex), Globals.Log_Leavel_ERROR, Globals.Log_Type_UPLOAD);
				    	continue;
				    }
				}
				
			    j.setMsg("导入成功"+succCnt+"条,失败"+errCnt+"条记录！");					
			    systemService.addLog("批量导入班组日数据"+succCnt+"条记录成功", Globals.Log_Leavel_INFO, Globals.Log_Type_UPLOAD);
			} catch (Exception e) {
				logger.error(ExceptionUtil.getExceptionMessage(e));
			}finally{
				try {
					file.getInputStream().close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return j;
	}
	
	/**
	 * 班组月数据维护模板
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(params = "exportXlsByMdataT")
	public String exportXlsByMdataT(HttpServletRequest request,HttpServletResponse response
			, DataGrid dataGrid,ModelMap modelMap) {		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("exportUserName", ResourceUtil.getSessionUserName().getRealName());
		
        modelMap.put(TemplateExcelConstants.FILE_NAME,"班组重点工作月数据列表");
        modelMap.put(TemplateExcelConstants.PARAMS,new TemplateExportParams("export/template/teamMonthData.xls",0));
        modelMap.put(TemplateExcelConstants.MAP_DATA,map);
        return TemplateExcelConstants.JEECG_TEMPLATE_EXCEL_VIEW;
        
	}
	
	/**
	 * 班组月数据导入功能跳转
	 *
	 * @return
	 */
	@RequestMapping(params = "uploadMonthForm")
	public ModelAndView uploadMonthForm(HttpServletRequest request) {
		 
		
		return new ModelAndView("com/buss/monthdata_excel_upload");
	}
	
	/**
	 * 导入班组月数据
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(params = "importMonthExcel", method = RequestMethod.POST)
	@ResponseBody
	public AjaxJson importMonthExcel(HttpServletRequest request, HttpServletResponse response) {		
		AjaxJson j = new AjaxJson();
		//班组名称
		String bzName = "";
		//用检员
		String checkerName = "";
		//月份
	    String cMonth ="";

		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
			MultipartFile file = entity.getValue();// 获取上传文件对象
			ImportParams params = new ImportParams();
			params.setTitleRows(2);
			params.setHeadRows(1);
			params.setNeedSave(true);
			int succCnt = 0;
			int errCnt = 0;
			try {
				List<CheckerMdata> cMdatas = ExcelImportUtil.importExcel(file.getInputStream(),CheckerMdata.class,params);
				List<Object> listGC = null;
				//验证班组及用检员是否存在
				for(CheckerMdata mdata:cMdatas){
					bzName = mdata.getBzName().trim();
					checkerName = mdata.getCheckerName().trim();
					cMonth = mdata.getCreateMonth().trim();
					
				    listGC = systemService.findHql("from CheckerInfo where bzName = ? and checkerName = ?", bzName,checkerName);
				    if(listGC==null || listGC.size()==0){
				    	  j.setMsg(mdata.getBzName()+"|"+mdata.getCheckerName()+" 班组用检员信息不存,请联系系统管理员！");	
				    	  return j;
				    } 
				    
				    if(cMonth.length()!=7 || cMonth.indexOf("-")==-1){
				    	j.setMsg(cMonth+" 月份格式不正确，参考 yyyy-MM 请检查！");	
				    	return j;
				    }
				}
				
				//班组Map
				List<TeamInfo> listBZ = systemService.findHql("from TeamInfo where state='1'");
				Map bzMap = new HashMap();
				for(TeamInfo ti:listBZ){
					bzMap.put(ti.getBzName(), ti.getBzId());
				}
				
				for(CheckerMdata mdata:cMdatas){
					bzName = mdata.getBzName().trim();
					checkerName = mdata.getCheckerName().trim();
					cMonth = mdata.getCreateMonth().trim();
				    
					mdata.setBzId(bzMap.get(bzName).toString());
				    
					mdata.setBzName(bzName);
					mdata.setCheckerName(checkerName);
					mdata.setCreateMonth(cMonth);
				    try{
				    	this.systemService.save(mdata);
				    	succCnt++;
				    }catch(Exception ex){
				    	errCnt++;
				    	systemService.addLog("导入班组月数据失败："+mdata.getCreateMonth()+"|"+mdata.getBzName()+"|"+mdata.getCheckerName()+"|"+ExceptionUtil.getExceptionMessage(ex), Globals.Log_Leavel_ERROR, Globals.Log_Type_UPLOAD);
				    	continue;
				    }
				}
				
			    j.setMsg("导入成功"+succCnt+"条,失败"+errCnt+"条记录！");					
			    systemService.addLog("批量导入班组月数据"+succCnt+"条记录成功", Globals.Log_Leavel_INFO, Globals.Log_Type_UPLOAD);
			} catch (Exception e) {
				logger.error(ExceptionUtil.getExceptionMessage(e));
			}finally{
				try {
					file.getInputStream().close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return j;
	}
}
